package edu.nf.ch12.config;

import edu.nf.ch12.anno.MyAnno;
import edu.nf.ch12.service.UserService;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StringUtils;

import java.util.ArrayList;

/**
 * @author wangl
 * @date 2025/4/30
 * 自定义导入选择器
 * 如果类上标注了@MyAnno注解，就将其纳入Spring容器管理
 */
public class AnnoImportSelector implements ImportSelector {

    /**
     * 返回值的String[]是一个完整类名的字符串数组
     * @param importingClassMetadata
     * @return
     */
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        ArrayList<String> list = new ArrayList<>();
        if(UserService.class.isAnnotationPresent(MyAnno.class)) {
            list.add(UserService.class.getName());
        }
        return StringUtils.toStringArray(list);
    }
}